<?php
namespace app\backend\controller;

use app\backend\model\Menu as MenuModel;
use think\Request;

class Menu extends Base
{
    public function index()
    {
        $model = model("Menu");
        $result = $model->getnav();

         //var_dump($result);
        $this->assign('menu',$result);
        $this->assign('empty',"暂无数据");
        return $this->fetch();
    }


    public function create()
    {
        if (Request::instance()->isPost()){
            $model = model("Menu");
            $post = Request::instance()->post();// 获取经过过滤的全部post变量
            //Request::instance()->post(false); // 获取全部的post原始变量

            //验证表单并插入数据库
            $result = $this->validate($post,'Modules.add');
            if(true !== $result){
                // 验证失败 输出错误信息
                //dump($result);
                return $this->error($msg = '参数错误，验证失败');
            }
            $model->insert($post);
        };
        return $this->fetch();
    }

    public function delete($id)
    {
        MenuModel::destroy($id);
        $this->redirect('modules/index');
        return $this->fetch();
    }

}